package com.zlm.tools.util;

/**
 * @author zlm
 * @date 2023/8/5
 */
public class ExceptionUtil {

    /**
     * 获取指定包名为前缀的堆栈异常信息
     * @param e 异常
     * @param packagePrefix 包前缀
     * @return 堆栈信息
     */
    public static String getStackTraceByPn(Throwable e,String packagePrefix){
        StringBuilder str = new StringBuilder("\n").append(e);
        for (StackTraceElement traceElement : e.getStackTrace()) {
            if(!traceElement.getClassName().startsWith(packagePrefix)){
                continue;
            }
            str.append("\n\tat ").append(traceElement);
        }
        return str.toString();

    }
}
